//index.js
//获取应用实例
const app = getApp()

const constant = require("../../constant.js")
const storage = require("../../utils/storage.js")
const auth = require("../../utils/auth.js")

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    qiniu: constant.resource.qiniu,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },

  onLoad: function (options) {

    var that = this;

    // debug or not
    if (options.debug) {
      wx.setEnableDebug({
        enableDebug: true
      })
    }

    // set device info into storage
    try {
      var res = wx.getSystemInfoSync()
      wx.setStorageSync(storage.keys.platform, res.platform)
      wx.setStorageSync(storage.keys.system, res.system)
    } catch (e) {
      console.log(e)
    }
  },

  

  onShow: function () {
    
    // do auth here
    auth.login(function () {
      console.log("登录成功")
      wx.redirectTo({
        url: '../profile/profile',
      })
    }, function () {
      console.log("登录失败")
      wx.redirectTo({
        url: '../auth-error/auth-error',
      })
    });

  }
})
